package com.victor.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.victor.dao.AdminToMenuOneDao;
import com.victor.dao.AdminToMenuTwoDao;
import com.victor.dao.AdministratorDao;
import com.victor.dao.MenuOneDao;
import com.victor.dao.MenuTwoDao;
import com.victor.entity.AdminToMenuOne;
import com.victor.entity.AdminToMenuTwo;
import com.victor.entity.Administrator;
import com.victor.entity.MenuOne;
import com.victor.entity.MenuTwo;
import com.victor.entity.step.Schedule;
import com.victor.entity.step.StepDetails;
import com.victor.service.AdministratorService;

@Service
public class AdministratorServiceImpl implements AdministratorService{
	@Autowired
	private MenuOneDao MenuOneDao;
	@Autowired
	private MenuTwoDao menuTwoDao;
	@Autowired
	private AdministratorDao administratorDao;
	@Autowired
	private AdminToMenuOneDao admintomenuoneDao;
	@Autowired
	private AdminToMenuTwoDao admintomenutwoDao;

	@Override
	public boolean insertOne(MenuOne one) {
		return MenuOneDao.insertSelective(one);
	}

	@Override
	public boolean insertTwo(MenuTwo menuTwo) {
		return menuTwoDao.insertSelective(menuTwo);
	}

	@Override
	public boolean updateOne(MenuOne menuOne) {
		return MenuOneDao.updateByPrimaryKeySelective(menuOne);
	}

	@Override
	public Boolean updateTwo(MenuTwo menuTwo) {
		return menuTwoDao.updateByPrimaryKeySelective(menuTwo);
	}

	@Override
	public boolean deleteOne(int[] id) {
		return MenuOneDao.delete(id);
	}

	@Override
	public boolean deleteTwo(int[] id) {
		return menuTwoDao.delete(id);
	}

	@Override
	public PageInfo<MenuOne> getMenu(int page,int row) {
		PageHelper.startPage(page, row);
		List<MenuOne> list = MenuOneDao.selectByPrimaryKey();
		return new PageInfo<>(list, 5);
	}

	@Override
	public boolean insert(Administrator administrator) {
		return administratorDao.insertSelective(administrator);
	}

	@Override
	public boolean insertAdminMenuOne(AdminToMenuOne adminToMenuOne) {
		return admintomenuoneDao.insert(adminToMenuOne);
	}

	@Override
	public boolean insertAdminMenuTwo(AdminToMenuTwo adminToMenuTwo) {
		return admintomenutwoDao.insert(adminToMenuTwo);
		
	}

	@Override
	public boolean deleteMenuOneTwo(String admin_id) {
		return admintomenuoneDao.deleteAdminOneAndTwo(admin_id);
	}

	@Override
	public List<AdminToMenuOne> getByAdminId(String admin_id) {
		return admintomenuoneDao.selByAdminid(admin_id);
	}

	@Override
	public boolean updateAdministrator(Administrator administrator) {
		return administratorDao.updateByPrimaryKeySelective(administrator);
	}

	@Override
	public boolean delAdministrator(int[] ids) {
		return administratorDao.deleteByPrimaryKey(ids);
	}

	@Override
	public Administrator getAdminById(Administrator administrator) {
		return administratorDao.selectByPrimaryKey(administrator);
	}

	@Override
	public PageInfo<Administrator> getAllAdmin(Integer page, Integer row) {
		PageHelper.startPage(page, row);
		List<Administrator> list = administratorDao.selALL();
		return new PageInfo<>(list, 5);
	}

	@Override
	public List<Administrator> getAll() {
		return administratorDao.selALL();
	}

	@Override
	public List<Administrator> selBySearch(String search) {
		return administratorDao.selBySearch(search);
	}

	@Override
	public PageInfo<Administrator> selByTime(String start, String end, int page, int row) {
		PageHelper.startPage(page, row);
		List<Administrator> list = administratorDao.selByTime(start,end);
		return new PageInfo<>(list, 5);
	}

	@Override
	public Administrator findByOpenid(String openId) {
		return administratorDao.selByOpenid(openId);
	}

	@Override
	public boolean delMenuTwo(String admin_id, String menuoneid) {
		return admintomenutwoDao.delMenutotwo(admin_id,menuoneid);
	}

	@Override
	public Administrator selByPhone(String a_username) {
		return administratorDao.selByPhone(a_username);
	}

	/**
	 * 	查询审批流程是否用到此员工
	 */
	@Override
	public List<StepDetails> selectStepDetails(String id) {
		return administratorDao.selectStepDetails(id);
	}

	/**
	 * 	删除此员工工作流程
	 */
	@Override
	public boolean delstepDetails(Integer sd_id) {
		return administratorDao.delstepDetails(sd_id);
	}
	
	/**
	 * 	查询此模板下所有流程表
	 */
	@Override
	public List<StepDetails> selectStepDetailsByS_id(Integer s_id,Integer position) {
		return administratorDao.selectStepDetailsByS_id(s_id,position);
	}

	/**
	 * 	修改其后全部流程向前挪动一位
	 */
	@Override
	public boolean updatePosition(Integer sd_id, Integer position) {
		return administratorDao.updatePosition(sd_id,position);
	}

	/**
	 * 	查询审批进度中是否用到此员工
	 */
	@Override
	public List<Schedule> selectSchedules(String id) {
		return administratorDao.selectSchedules(id);
	}

	/**
	 * 	删除该员工审核进度
	 */
	@Override
	public boolean delSchedules(Integer id) {
		return administratorDao.delSchedules(id);
	}

	/**
	 * 	查询该模板下所有审核进度
	 */
	@Override
	public List<Schedule> selectScheduleByS_id(String s_id, Integer sp_sequence) {
		return administratorDao.selectScheduleByS_id(s_id,sp_sequence);
	}

	/**
	 * 修改审核进度
	 */
	@Override
	public boolean updateScheduleById(Schedule schedule) {
		return administratorDao.updateScheduleById(schedule);
	}

	

}
